﻿#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PySide6 import QtCore, QtGui,QtWidgets
from ui_setting import Ui_DlgSettingClass
from PySide6.QtWidgets import  QFileDialog
import config_json
class DlgSetting(QtWidgets.QDialog):
    def __init__(self, parent=None):
        print("init")
        super(DlgSetting, self).__init__(parent)
        self.ui=Ui_DlgSettingClass()
        self.ui.setupUi(self)
        self.ui.lineEdit.setText(config_json.setting["database"])
        self.ui.lineEdit_2.setText(config_json.setting["output_folder"])
        self.ui.lineEdit_yqbh.setText(config_json.setting["yqbh"])
        self.ui.btnSelect.clicked.connect(self.select)
        self.ui.btnOutput.clicked.connect(self.select2)
        ii=0
        at=0
        for i in ["cs","onh"]:
            if i== config_json.setting2.value("sblx"):
                at=ii
            self.ui.cmb_sblx.addItem(i)
            ii+=1
        self.ui.cmb_sblx.setCurrentIndex(at)
        # self.ui.cmb_sblx.setEditable(True)

        # self.ui.cmb_sblx.currentIndexChanged[int].connect(self.sblx_change)

    def select(self):
        FileDialog = QFileDialog(self)
        FileDirectory = FileDialog.getOpenFileName(self,'select database file')                #选择目录，返回选中的路径
        print(FileDirectory)
        self.ui.lineEdit.setText(FileDirectory[0])
    def select2(self):
        FileDialog = QFileDialog(self)
        FileDirectory = FileDialog.getExistingDirectory(self,'select output folder')                #选择目录，返回选中的路径
        print(FileDirectory,type(FileDirectory),dir(FileDirectory))
        if FileDirectory!="":
            self.ui.lineEdit_2.setText(FileDirectory)
        else:
            print("not select")
    #@QtCore.pyqtSlot()
    def accept(self):
        print("accept")
        config_json.setting['database']=self.ui.lineEdit.text()
        config_json.setting['output_folder']=self.ui.lineEdit_2.text()
        config_json.setting['yqbh']=self.ui.lineEdit_yqbh.text()
        config_json.setting['sblx']=self.ui.cmb_sblx.currentText()
        # config_json.write_setting()
        self.done(1)
        pass
    #@QtCore.pyqtSlot()
    def reject(self):
        print("reject")
        self.done(0)
        pass
def main():        
    import sys
    app = QtWidgets.QApplication(sys.argv)
    calculator = DlgSetting()
    #calculator.showdata(9)
    #calculator.show()
    calculator.exec()
    #sys.exit(app.exec_())

if __name__ == '__main__':
    main()
